/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.view.purchaseView;
/**
 * 说明：
 * 进货管理主窗体
 * @Author：黄盛强
 * @Date：2012-03-20
 */
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.event.ActionEvent;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;

import com.ruipengkj.ApplicationContext;
import com.ruipengkj.commons.util.SwingUtil;
import com.ruipengkj.commons.util.Util;
import com.ruipengkj.view.base.BaseInternalFrame;

public class PurchaseInternalFrame extends BaseInternalFrame {

	private static final long serialVersionUID = 1L;
	
	private JToolBar toolBar;//工具栏
	
	private JPanel main;//主面板
	private CardLayout main_layout;//主面板布局
	
	private JButton purchaseEnterButton;//进货按钮
	private PurchaseEnterPanel purchaseEnterPanel;//进货面板
	
	private JButton purchaseRetreatButton;//退货按钮
	private PurchaseRetreatPanel purchaseRetreatPanel;//退货面板
	
	public PurchaseInternalFrame(String title, boolean resizable,
			boolean closable, boolean maximizable, boolean iconifiable) {
		super(title, resizable, closable, maximizable, iconifiable);
		init();
	}
	
	
	private void init(){
		this.setLayout(new BorderLayout());
		this.initComponents();
		this.initListener();
	}
	
	//初始化组件
	private void initComponents() {
		toolBar = new JToolBar();
		toolBar.setFloatable(false);//设置工具栏不可移动
		purchaseEnterButton=new JButton("采购进货",SwingUtil.getOpenSwingImage("purchase_enter.png"));
		purchaseRetreatButton=new JButton("采购退货",SwingUtil.getOpenSwingImage("purchase_return.png"));
		
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL41)){
			toolBar.add(purchaseEnterButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL42)){
			toolBar.add(purchaseRetreatButton);
		}
		
		
		main=new JPanel();
		main_layout=new CardLayout();
		main.setLayout(main_layout);
		
		this.add(toolBar,BorderLayout.NORTH);
		this.add(main,BorderLayout.CENTER);
	}
	//初始化监听器
	private void initListener() {
		purchaseEnterButton.addActionListener(this);
		purchaseRetreatButton.addActionListener(this);
	}
	
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==purchaseEnterButton){
			//进货按钮
			purchaseEnterPanel = new PurchaseEnterPanel();
			main.add(purchaseEnterPanel,"purchaseEnterPanel");
			main_layout.show(main, "purchaseEnterPanel");
			this.setTitle("进货管理--采购进货");
			Util.setButtonStatus(toolBar,purchaseEnterButton);
			SwingUtilities.invokeLater(purchaseEnterPanel);
		} else if(e.getSource()==purchaseRetreatButton){
			//退货按钮
			purchaseRetreatPanel = new PurchaseRetreatPanel();
			main.add(purchaseRetreatPanel,"purchaseRetreatPanel");
			main_layout.show(main, "purchaseRetreatPanel");
			this.setTitle("进货管理--采购退货");
			Util.setButtonStatus(toolBar,purchaseRetreatButton);
			SwingUtilities.invokeLater(purchaseRetreatPanel);
		}
		main.updateUI();
	}
	
	public void showButton(){
		if (toolBar != null && toolBar.getComponentCount() != 0)
			((JButton)toolBar.getComponent(0)).doClick();

	}
	
	public void showButton(int type){
		switch(type){
		case 1:{purchaseEnterButton.doClick();break;}
		case 2:{purchaseRetreatButton.doClick();break;}
	}
	}
}
